<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>滚动弹幕</title>
    <style>
        body {
            font-family: Arial, sans-serif;
            margin: 0;
            padding: 0;
            display: flex;
            flex-direction: column;
            align-items: center;
            justify-content: center;
            height: 100vh;
            background-color: #f0f0f0;
        }
        #danmu-container {
            position: relative;
            width: 80%;
            height: 200px;
            background-color: #333;
            overflow: hidden;
            margin-bottom: 20px;
        }
        .danmu {
            position: absolute;
            top: 20px;
            white-space: nowrap;
            color: white;
            font-size: 16px;
            padding: 5px 10px;
            background-color: rgba(0, 0, 0, 0.5);
            border-radius: 5px;
        }
        #speed-control {
            margin-top: 20px;
        }
        #danmu-input {
            margin-top: 20px;
            display: flex;
            gap: 10px;
        }
        #danmu-input input {
            padding: 5px;
            font-size: 16px;
        }
        #danmu-input button {
            padding: 5px 10px;
            font-size: 16px;
            cursor: pointer;
        }
    </style>
</head>
<body>
    <div id="danmu-container">
        <div class="danmu" style="left: 100%;">这是弹幕1</div>
        <div class="danmu" style="left: 110%;">这是弹幕2</div>
        <div class="danmu" style="left: 120%;">这是弹幕3</div>
    </div>
    <div id="speed-control">
        <label for="speed">弹幕速度：</label>
        <input type="range" id="speed" min="1" max="10" value="5">
    </div>
    <div id="danmu-input">
        <input type="text" id="danmu-text" placeholder="输入弹幕内容">
        <button id="send-danmu">发送弹幕</button>
    </div>

    <script>
        const danmuContainer = document.getElementById('danmu-container');
        const speedControl = document.getElementById('speed');
        const danmuInput = document.getElementById('danmu-text');
        const sendDanmuButton = document.getElementById('send-danmu');
        let speed = 5;

        function moveDanmu() {
            document.querySelectorAll('.danmu').forEach((danmu, index) => {
                let currentLeft = parseFloat(danmu.style.left) || 100;
                currentLeft -= speed;
                danmu.style.left = `${currentLeft}%`;

                if (currentLeft < -100) {
                    danmu.style.left = `100%`;
                }
            });
        }

        setInterval(moveDanmu, 100);

        speedControl.addEventListener('input', (e) => {
            speed = e.target.value;
        });

        sendDanmuButton.addEventListener('click', () => {
            const danmuText = danmuInput.value.trim();
            if (danmuText) {
                const newDanmu = document.createElement('div');
                newDanmu.classList.add('danmu');
                newDanmu.style.left = '100%';
                newDanmu.textContent = danmuText;
                danmuContainer.appendChild(newDanmu);
                danmuInput.value = '';
            }
        });
    </script>
</body>
</html>